<template>
  <a-card :bordered="false"  v-show="isShowPage">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper" v-show="isShowQuery" >
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator" v-show="isShowOptBtn" >
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('cou_grade')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <template>
        <span style="float:right;">
          <a @click="searchQuery()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <a-button v-print="'#datatable'" ghost type="primary">打印</a-button>
        </span>
      </template>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;" v-show="isShowOptBtn">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange"
        :customRow="clickThenCheck">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!--分割线-->
<!--    <a-divider @click="handleTabsShowStatus" >分割线</a-divider> -->
    <a v-if="tabsShowOpetaterStatus" @click='handleTabsShowStatus' style='margin-left: 8px'>
      {{ tabsShowStatus ? '-' : '+' }}
      <a-icon :type="tabsShowStatus ? 'up' : 'down'" />
    </a>
    <!-- 折叠部分-->
    <template v-if='tabsShowStatus'>
<!--    <a-tabs :defaultActiveKey="this.tabsLists.key" @change="key => onTabChange(key, 'key')" >-->
<!--      <a-tab-pane tab="班级" key="CouClassList" >-->
<!--        <cou-class-list ref="CouClassList" :is-show-page="this.tabsLists.key === 'CouClassList' " :is-show-query='false' :is-show-opt-btn="false"  ></cou-class-list>-->
<!--      </a-tab-pane>-->
<!--      <a-tab-pane tab="老师" key="TeaTeacherList" forceRender>-->
<!--        <tea-teacher-list ref="TeaTeacherList" :is-show-page="this.tabsLists.key === 'TeaTeacherList' " :is-show-query='false' :is-show-opt-btn="false"  ></tea-teacher-list>-->
<!--      </a-tab-pane>-->
<!--    </a-tabs>-->
      <a-card
        style='width: 100%'
        :tab-list='tabsLists.tabList'
        :active-tab-key='tabsLists.key'
        @tabChange="key => onTabChange(key, 'key')"
      >
              <cou-class-list ref="CouClassList" :this-is-tab-page="true" :is-show-page="this.tabsLists.key === 'CouClassList' " :is-show-query='false' :is-show-opt-btn="false"  ></cou-class-list>
              <tea-teacher-list ref="TeaTeacherList" :this-is-tab-page="true" :is-show-page="this.tabsLists.key === 'TeaTeacherList' "  :is-show-query='false' :is-show-opt-btn="false"  ></tea-teacher-list>
              <cou-course-arrange-one-table  ref="CouCourseArrangeOneTable" :this-is-tab-page="true" :is-show-page="this.tabsLists.key === 'CouCourseArrangeOneTable' "  :is-show-query='false' :is-show-opt-btn="false" ></cou-course-arrange-one-table>
      </a-card>
    </template>


    <cou-grade-modal ref="modalForm" @ok="modalFormOk"></cou-grade-modal>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import CouGradeModal from './modules/CouGradeModal'
  import CouClassList from '@views/smart_school/classes/CouClassList'
  import TeaTeacherList from '@views/smart_school/teacher/TeaTeacherList'
  import CouCourseArrangeOneTable from '@views/smart_school/coursearrangePreview/CouCourseArrangeOneTable'
  export default {
    name: 'CouGradeList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      CouGradeModal,
      CouClassList,
      TeaTeacherList,
      //课表预览:全校课表一张表
      CouCourseArrangeOneTable,
    },
    props: {
      //变量优先级顺序：props的优先级>data中的优先级>methods中的优先级
      //是否显示全部页面
      isShowPage: {
        type: Boolean,
        default: true
      },
      //本页面是否是被引用的tab页面，tab页面隐藏部分组件
      thisIsTabPage: {
        type: Boolean,
        default: false
      },
      //是否显示查询条件
      isShowQuery: {
        type: Boolean,
        default: true
      },
      isShowOptBtn: {
        type: Boolean,
        default: true
      },
    },
    watch: {
      //如果本页是被引用的tab页，隐藏查询条件，隐藏操作按钮
      thisIsTabPage: function (val){
        if ( val ){
          this.isShowQuery = false
          this.isShowOptBtn = false
        }
      }

    },
    data () {
      return {
        description: 'cou_grade管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'年级编码',
            align:"center",
            dataIndex: 'gradeCode'
          },
          {
            title:'年级',
            align:"center",
            dataIndex: 'gradeName'
          },
          {
            title:'简称',
            align:"center",
            dataIndex: 'gradeAbbreviation'
          },
          {
            title:'年级阶段',
            align:"center",
            dataIndex: 'gradeStage_dictText'
          },
          {
            title:'下一年级(升级)',
            align:"center",
            dataIndex: 'gradeNextCode_dictText'
          },
          {
            title:'排序',
            align:"center",
            dataIndex: 'gradeOrder'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/grade/couGrade/list",
          delete: "/grade/couGrade/delete",
          deleteBatch: "/grade/couGrade/deleteBatch",
          exportXlsUrl: "/grade/couGrade/exportXls",
          importExcelUrl: "grade/couGrade/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        tabsShowOpetaterStatus: true,
        tabsShowStatus: true,

        tabsLists: {
          key: 'CouClassList',
          tabList: [
              {
                key: 'CouClassList',
                tab: '班级'
              },
              {
                key: 'TeaTeacherList',
                tab: '老师'
              },
            {
              key: 'CouCourseArrangeOneTable',
              tab: '课表'

            }
            ],
        }
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      handleTabsShowStatus(){
        this.tabsShowStatus = !this.tabsShowStatus;
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'gradeCode',text:'年级编码'})
        fieldList.push({type:'string',value:'gradeName',text:'年级名称'})
        fieldList.push({type:'string',value:'tenantId',text:'学校编码'})
        fieldList.push({type:'int',value:'gradeStage',text:'年级阶段'})
        fieldList.push({type:'string',value:'gradeNextCode',text:'下一年级编码'})
        fieldList.push({type:'int',value:'gradeOrder',text:'排序'})
        this.superFieldList = fieldList
      },
      //切换tab
      onTabChange(value, type) {
        this.tabsLists.key = value
        this.checkValueKeyIsShow(this.tabsLists.key)
        this.onSelectChange(this.selectedRowKeys, this.selectionRows)
      },
      //控制是否显示:控制显示哪一个tab
      checkValueKeyIsShow(key) {

      },
      //单击一行记录
      clickThenCheck(record) {
        return {
          on: {
            click: () => {
              this.onSelectChange(record.id.split(','), [record])
            }
          }
        }
      },
      //勾选，选中一行记录
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectionRows = selectionRows
        if (this.selectedRowKeys.length >= 1 && !this.thisIsTabPage ) {
          //封装查询条件
          var refsTabQueryParam = {gradeId:this.selectedRowKeys[0]}
          console.log("CouGradeList.refsTabQueryParam="+refsTabQueryParam+",p.gradeId="+refsTabQueryParam.gradeId)

          if (this.tabsLists.key === "CouClassList"){
            //调用查询方法
            this.$refs.CouClassList.getOrderMain(refsTabQueryParam)
          }else if (this.tabsLists.key === "TeaTeacherList"){
            //调用查询方法
            this.$refs.TeaTeacherList.getOrderMain(refsTabQueryParam)
          }else if (this.tabsLists.key === "CouCourseArrangeOneTable"){
            //调用查询方法
            this.$refs.CouCourseArrangeOneTable.getOrderMain(refsTabQueryParam)
          }

        }
      },
      //取消选中
      onClearSelected() {
        this.selectedRowKeys = []
        this.selectionRows = []
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>